#!/bin/bash
source ../var.install

#check if file contain specific string
function FileContainStr
{

	file=$1
		str=$2

		if [ ! -f $file ];
	then
		return 0;
	fi
		tmp=$(grep -InR $str $file)
		if [ -z "$tmp" ];
	then
		return 0
		fi
		return 1
}

MYSYMBOL1=Johnny_bash_aliases
function IsMyFile
{
	FILE=$1
	FileContainStr $FILE $MYSYMBOL1 
	if [ $? -eq 0 ];
	then
		return 0
	fi
	return 1
}
#show installing message
ShowInstallPackage "Set aliases"

#backup old bash_alises if new
ALSFILE=~/.bash_aliases
ALSFILE_BAK=~/.bash_aliases.old
IsMyFile $ALSFILE
if [ $? -eq 0 ];
then
	echo "backup old aliases file : $ALSFILE_BAK"
	cp $ALSFILE $ALSFILE_BAK 
fi

#add new aliases
echo "copy bash_aliases file and aliases folder"
rm ~/.aliases -rf
cp ./aliases ~/.aliases -rf
cp bash_aliases ~/.bash_aliases 

ShowInstallPackage "Set Global Path"
#add command path into PATH string
currentPath=$(echo $(pwd))
cd $currentPath/command/
source setPathGlobal.sh 
cd ..

cd ..
cd ..
cd NetAXS
source setPathGlobal.sh 
cd $currentPath
#setPathGlobal would run the aliases already , so no need to run again
#source ~/.bash_aliases
